

#ifndef UD_DIMREFPT_H
#define UD_DIMREFPT_H


typedef UcArray<UcDbFullSubentPath, UcArrayObjectCopyReallocator<UcDbFullSubentPath> >
	UcDbFullSubentPathArray;

typedef UcArray<UcDbHandle, UcArrayObjectCopyReallocator<UcDbHandle> >
	UcDbHandleArrayPtRef;

class UcDbPointRef : public UcRxObject
{
public:
	UCRX_DECLARE_MEMBERS(UcDbPointRef);

	enum OsnapType { 
		kOsnapNone         = 0,
		kOsnapEnd          = 1,
		kOsnapMid          = 2,
		kOsnapCen          = 3,
		kOsnapNode         = 4,
		kOsnapQuad         = 5, 
		kOsnapInt          = 6,
		kOsnapIns          = 7,
		kOsnapPerp         = 8,
		kOsnapTan          = 9,
		kOsnapNear         = 10,
		kOsnapApint        = 11,
		kOsnapPar          = 12,
		kOsnapStart        = 13
	};

	virtual UcDbPointRef& operator=(const UcDbPointRef& src);
	virtual Ucad::ErrorStatus evalPoint(UcGePoint3d& pnt_wcs)=0; 
	virtual Ucad::ErrorStatus getEntities(UcDbFullSubentPathArray& ents,
							  bool getLastPtRef = true) const=0;
	virtual bool              isGeomErased() const=0;
	virtual bool              isXrefObj(UcDbObjectIdArray& ids1,
										UcDbObjectIdArray& ids2,
										bool isMainObj = true) const=0;
	virtual Ucad::ErrorStatus updateXrefSubentPath()=0;

	virtual Ucad::ErrorStatus dwgOutFields(UcDbDwgFiler* filer,
										   UcDbDatabase* pDb) const=0;
	virtual Ucad::ErrorStatus dwgInFields(UcDbDwgFiler* filer,
										  UcDbDatabase* pDb)=0;
	virtual Ucad::ErrorStatus dxfOutFields(UcDbDxfFiler* filer,
										   UcDbDatabase* pDb) const=0;
	virtual Ucad::ErrorStatus dxfInFields(UcDbDxfFiler* filer,
										  UcDbDatabase* pDb)=0;

	virtual Ucad::ErrorStatus subErase(ZSoft::Boolean erasing) 
								{return Ucad::eOk;}
	virtual Ucad::ErrorStatus wblockClone(UcRxObject* pOwnerObject,
										  UcDbObject*& pClonedObject,
										  UcDbIdMapping& idMap,
										  ZSoft::Boolean isPrimary = ZSoft::kTrue)
										  const {return Ucad::eOk;}
	virtual Ucad::ErrorStatus deepClone(UcRxObject* pOwnerObject,
										UcDbObject*& pClonedObject,
										UcDbIdMapping& idMap,
										ZSoft::Boolean isPrimary = ZSoft::kTrue)
										const {return Ucad::eOk;}

	static Ucad::ErrorStatus  dwgInFields(UcDbDwgFiler* filer,
										  UcDbDatabase* pDb,
										  UcDbPointRef*& pPointRef);
	static Ucad::ErrorStatus  dwgOutFields(UcDbDwgFiler* filer,
										   UcDbDatabase* pDb,
										   const UcDbPointRef* pPointRef);
	static Ucad::ErrorStatus  dxfInFields(UcDbDxfFiler* filer,
										  UcDbDatabase* pDb,
										  UcDbPointRef*& pPointRef);
	static Ucad::ErrorStatus  dxfOutFields(UcDbDxfFiler* filer,
										   UcDbDatabase* pDb,
										   const UcDbPointRef* pPointRef);

	static UcDbEntity*        subentPtr(const UcDbFullSubentPath& objPath, 
										bool& isCloned, bool& reverseArc);
	static bool               calcTransform(const UcDbObjectIdArray& ids,
											UcGeMatrix3d& A_Ecs2Wcs);
	static UcGeMatrix3d       wcsToDcsMatrix(const UcDbViewport* pVPort);
	static UcGeMatrix3d       mswcsToPswcs(const UcDbViewport* pVPort);
};

class UcDbOsnapPointRef : public UcDbPointRef
{
public:
	UCRX_DECLARE_MEMBERS(UcDbOsnapPointRef);

	UcDbOsnapPointRef();
	UcDbOsnapPointRef(const UcGePoint3d& refPt);
	UcDbOsnapPointRef(UcDbPointRef::OsnapType osnapType, 
					  const UcDbFullSubentPath *objPath, 
					  const UcDbFullSubentPath *intObjPath = NULL,
					  const UcGePoint3d *refPt = NULL,
					  UcDbPointRef* lastPtRef = NULL);
	UcDbOsnapPointRef(const UcDbOsnapPointRef& src);
	virtual ~UcDbOsnapPointRef();

	virtual UcDbPointRef& operator= (const UcDbPointRef& src);
	UcDbOsnapPointRef& operator= (const UcDbOsnapPointRef& src);

	UcDbPointRef::OsnapType osnapType() const;
	Ucad::ErrorStatus  setOsnapType(UcDbPointRef::OsnapType osnType);

	Ucad::ErrorStatus  getIdPath(UcDbFullSubentPath& idPath) const;
	Ucad::ErrorStatus  setIdPath(const UcDbFullSubentPath& idPath);

	Ucad::ErrorStatus  getIntIdPath(UcDbFullSubentPath& intIdPath) const;
	Ucad::ErrorStatus  setIntIdPath(const UcDbFullSubentPath& intIdPath);

	Ucad::ErrorStatus  setLastPointRef(UcDbPointRef *ptRef);
	UcDbPointRef*      lastPointRef() const;

	Ucad::ErrorStatus  setPoint(const UcGePoint3d& pt);
	UcGePoint3d        point() const;

	double             nearPointParam() const;
	Ucad::ErrorStatus  setNearPointParam(double newVal);

	virtual bool       isGeomErased() const;
	virtual bool       isXrefObj(UcDbObjectIdArray& ids1,
								 UcDbObjectIdArray& ids2,
								 bool isMainObj = true) const;
	virtual Ucad::ErrorStatus updateXrefSubentPath();
	virtual Ucad::ErrorStatus evalPoint(UcGePoint3d &pt);

	virtual Ucad::ErrorStatus getEntities(UcDbFullSubentPathArray& ents,
										  bool getLastPtRef = true) const;
	virtual Ucad::ErrorStatus copyFrom(const UcRxObject* pSrc);
	virtual Ucad::ErrorStatus dwgInFields(UcDbDwgFiler* filer,
										  UcDbDatabase* pDb);
	virtual Ucad::ErrorStatus dwgOutFields(UcDbDwgFiler* filer,
										   UcDbDatabase* pDb) const;
	virtual Ucad::ErrorStatus dxfInFields(UcDbDxfFiler* filer,
										  UcDbDatabase *pDb);
	virtual Ucad::ErrorStatus dxfOutFields(UcDbDxfFiler* filer,
										   UcDbDatabase *pDb) const;

	Ucad::ErrorStatus  getXrefHandles(UcDbHandleArrayPtRef& xrefHandles) const;
	Ucad::ErrorStatus  setXrefHandles(const UcDbHandleArrayPtRef& xrefHandles);

	Ucad::ErrorStatus  getXrefIntHandles(UcDbHandleArrayPtRef& xrefHandles) const;
	Ucad::ErrorStatus  setXrefIntHandles(const UcDbHandleArrayPtRef& xrefHandles);

protected:
	UcGePoint3d        nearPoint();
	double             findNearPointParam(const UcGePoint3d& pt) const;
	bool               getEllipseParams(double& sP, double& eP) const;
	bool               isTransSpatial(bool isMainObj = true) const;

	Ucad::ErrorStatus  evalPointGuts(UcDbPointRef::OsnapType ospType,
									 const UcGePoint3d& pickPt,
									 const UcGePoint3d& lastPt,
									 UcGePoint3d &pt);

	Ucad::ErrorStatus  getIntPoints(const UcDbEntity* pEnt,
									const UcDbEntity* pIntEnt,
									UcDb::Intersect intType,
									UcGePoint3dArray& intPts,
									int gsMarker1 = 0,
									int gsMarker2 = 0) const;

private:
	OsnapType          mOsnapType;
	UcDbFullSubentPath mObjPath;
	UcDbFullSubentPath mIntObjPath;
	double             mNearPointParam;
	UcGePoint3d        mPoint;
	UcDbPointRef*      mpLastPointRef;

	UcDbHandleArrayPtRef    mHandleArray;
	UcDbHandleArrayPtRef    mIntHandleArray;
};

#endif //UD_DIMREFPT_H
